package com.cn.wanxi.service;

import com.cn.wanxi.dao.NavDao;
import com.cn.wanxi.model.NavModel;
import com.cn.wanxi.model.NewsModel;
import com.cn.wanxi.model.ProductModel;
import com.cn.wanxi.util.IO;
import com.cn.wanxi.util.PAHT;
import com.cn.wanxi.util.Tool;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 控制公司导航层
 */
public class NavService {
    private String split = PAHT.SPLIT.getPath();

    /**
     * 得到头部导航
     * @return
     */
    public ArrayList<NavModel> getNavModelListForHome() {
        List<String> hrefsList = new ArrayList();
        List<String> titlesList = new ArrayList();
        NavDao navDao = new NavDao();
        int length = navDao.getHrefsList().size();
        for (int i = 0; i <length; i++) {
            hrefsList.add(navDao.getHrefsList().get(i));
            titlesList.add(navDao.getTitlesList().get(i));
        }
        String Hrefs = Tool.replaceText(hrefsList.toString());
        String Titles = Tool.replaceText(titlesList.toString());
        String addStr = Hrefs+split+Titles;
        //写
        IO.writeNotepad(addStr, PAHT.NAVSERVICE_FILE_NAME.getPath());
        //读
        String[] str = IO.readNotepad().split(split);//aaaaaa@@@@bbbbbbb
        List<String> List=new ArrayList(Arrays.asList(str));//集合1{a,a,a,a,a,a,a}和集合2{b,b,b,b,b,b,b,b}
        ArrayList<NavModel> navModelList = new ArrayList<>();
        for (int i = 0; i <length; i++) {
            NavModel navModel = new NavModel();
            navModel.setHref(List.get(0).split(",")[i]);
            navModel.setTitle(List.get(1).split(",")[i]);
            navModelList.add(navModel);
        }
        return navModelList;
    }

    /**
     * /得到关于我们的集合
     * @return
     */
    public  ArrayList<NavModel> getNavModelListForAboutUs() {
        List<String> hrefsList = new ArrayList();
        List<String> titlesList = new ArrayList();

        ArrayList<NavModel> navModelList = new ArrayList<>();
        NavDao navDao = new NavDao();
        int length = navDao.getNavAboutUsTilesList().size();
        for (int i = 0; i <length; i++) {
            hrefsList.add(navDao.getNavAboutUsHrefsList().get(i));
            titlesList.add(navDao.getNavAboutUsTilesList().get(i));
        }
        String Hrefs = Tool.replaceText(hrefsList.toString());
        String Titles = Tool.replaceText(titlesList.toString());
        String addStr = Hrefs+split+Titles;
        //写
        IO.writeNotepad(addStr, PAHT.NAVSERVICE_FILE_NAME.getPath());
        //读
        String[] str = IO.readNotepad().split(split);//aaaaaa@@@@bbbbbbb
        List<String> List=new ArrayList(Arrays.asList(str));//集合1{a,a,a,a,a,a,a}和集合2{b,b,b,b,b,b,b,b}


        for (int i = 0; i <length; i++) {
            NavModel navModel = new NavModel();
            navModel.setHref(List.get(0).split(",")[i]);
            navModel.setTitle(List.get(1).split(",")[i]);
            navModelList.add(navModel);
        }
        return navModelList;
    }

    /**
     * d得到新闻的导航  你好
     * @return
     */
    public ArrayList<NavModel> getNavModelListForNewsCenter() {
        List<String> hrefsList = new ArrayList();
        List<String> titlesList = new ArrayList();
        ArrayList<NavModel> navModelList = new ArrayList<>();
        NavDao navDao = new NavDao();
        int length = navDao.getNavNewsHrefsList().size();
        for (int i = 0; i <length; i++) {
            NavModel navModel = new NavModel();
            hrefsList.add(navDao.getNavNewsHrefsList().get(i));
            titlesList.add(navDao.getNavNewsTilesList().get(i));
        }
        String Hrefs = Tool.replaceText(hrefsList.toString());
        String Titles = Tool.replaceText(titlesList.toString());
        String addStr = Hrefs+split+Titles;
        //写
        IO.writeNotepad(addStr, PAHT.NAVSERVICE_FILE_NAME.getPath());
        //读
        String[] str = IO.readNotepad().split(split);//aaaaaa@@@@bbbbbbb
        List<String> List=new ArrayList(Arrays.asList(str));//集合1{a,a,a,a,a,a,a}和集合2{b,b,b,b,b,b,b,b}


        for (int i = 0; i <length; i++) {
            NavModel navModel = new NavModel();
            navModel.setHref(List.get(0).split(",")[i]);
            navModel.setTitle(List.get(1).split(",")[i]);
            navModelList.add(navModel);
        }
        return navModelList;
    }
}
